/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newpackage;

/**
 *
 * @author user
 */
import java.io.BufferedReader; 
import java.io.FileReader; 
public class CountWord 
{ 
    public static int getCount(String path)
{ 
    int count=0;
    CountWord s=new CountWord(); 
try 
{ 
    count=s.start(path); 
} catch(Exception e)
{ System.out.print("Some problem occured"); }
return count;

} 
public int start(String path) throws Exception { 
    FileReader fr=null;
    int totword=0;
    BufferedReader br=null;
try { 
    fr=new FileReader(path); 
br=new BufferedReader(fr);
String line=br.readLine(); 
 while(line!=null) 
{ String a[]=line.split(" "); for(int i=0;i<a.length;i++) 
{ if(a[i].length()>0) totword+=1; } line=br.readLine(); } 
System.out.print("Total number of words"+totword); br.close(); }
catch(Exception e) 
{ e.printStackTrace(); System.out.println("error"+e.getMessage()); } 
finally { br.close(); fr.close(); } 
return totword;
} }

